package com.pys.common.beans;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import java.util.TimeZone;

import javax.faces.bean.ApplicationScoped;
import javax.faces.bean.ManagedBean;
import javax.faces.context.FacesContext;

import org.primefaces.context.RequestContext;

import com.pys.utils.FacesUtils;

@ApplicationScoped
@ManagedBean(name = "Application", eager = true)
public class ApplicationBean implements Serializable {
	/**
	 *
	 */
	private static final long serialVersionUID = 1L;
	private String contextRoot = null;

	public ApplicationBean() {

	}

	public String getMoneyPattern() {
		return "#,##0.00";
	}

	public String getLongPattern() {
		return "#,##0";
	}

	public String getShortDatePattern() {
		return "dd/MM/yyyy";
	}

	public String getLongDatePattern() {
		return "dd/MM/yyyy HH:mm:ss";
	}

	public TimeZone getTimeZone() {
		return TimeZone.getTimeZone("GMT+02:00");
	}

	public String getDefaultCurrency() {
		return "TL";
	}

	public String getLoginImagePath() {
		return "/resources/images/login/";
	}

	public String getImagePath() {
		return "/resources/images/"
				+ FacesUtils.getUserSession().getLocale().toString() + "/";
	}

	// public String getThemeImagePath() {
	// return "/resources/images/themes/"
	// + FacesUtils.getUserSession().getTheme().getLabel()
	// .toLowerCase(Locale.ENGLISH) + "/";
	// }
	//
	// public String getLocaleMenuImagePath() {
	// return "/resources/images/"
	// + FacesUtils.getUserSession().getLocale().toString()
	// + "/menu/"
	// + FacesUtils.getUserSession().getTheme().getLabel()
	// .toLowerCase(Locale.ENGLISH) + "/";
	// }
	//
	// public String getMenuImagePath() {
	// return "/resources/images/themes/"
	// + FacesUtils.getUserSession().getTheme().getLabel()
	// .toLowerCase(Locale.ENGLISH) + "/menu/";
	// }

	// public Converter getEetDateConverter() {
	// return new EETDateConverter();
	// }
	//
	// public boolean isProdEnvironment() {
	// return ApplicationParameter.getInstance().isProdEnvironment();
	// }
	//
	// public boolean isTestEnvironment() {
	// return ApplicationParameter.getInstance().isTestEnvironment();
	// }
	//
	// public boolean isDevEnvironment() {
	// return ApplicationParameter.getInstance().isDevEnvironment();
	// }
	//
	// public String getServerInfo() {
	// return ApplicationUtils.getServerInfo();
	// }
	//
	// public String getServerIP() {
	// return ApplicationUtils.getServerIP();
	// }

	public String getViewId() {
		try {
			return FacesContext.getCurrentInstance().getViewRoot().getViewId();
		} catch (Exception e) {
			e.printStackTrace();
			return "";
		}
	}

	public String getContextRoot() {
		if (contextRoot == null) {
			contextRoot = FacesContext.getCurrentInstance()
					.getExternalContext().getRequestContextPath();
		}
		return contextRoot;
	}

	public void getLink() {
		Map<String, String> params = FacesUtils.getFacesContext()
				.getExternalContext().getRequestParameterMap();
		String link = params.get("link");

		Map<String, Object> options = new HashMap<String, Object>();
		options.put("modal", true);
		options.put("draggable", true);
		options.put("resizable", false);
		options.put("contentHeight", 700);
		options.put("contentWidth", 800);

		RequestContext.getCurrentInstance().openDialog(link, options, null);

		// return link + "?faces-redirect=true";
	}

	// LoginTemplate.xhtml de kullaniliyor
	// public String getServerName() {
	// String serverIpAddress = getServerIP();
	// String serverID;
	//
	// CmnApplicationServers server = ApplicationServerCache.getInstance()
	// .findByIp(serverIpAddress);
	//
	// if (server != null) {
	// serverID = server.getServerId().toString();
	// } else {
	// // Varsayilan olarak Sunucu IP adresinin son sayisini ID olarak
	// // kabul edelim.
	// serverID = serverIpAddress.split("\\.")[3];
	// }
	// return "int_" + serverID;
	// }

}
